using System;
using System.Collections.Generic;
using Activa.LazyParser;
using Activa.SharpTemplate;
using Activa.SharpTemplate.Config;

namespace UnitTests
{
	public class VelocityTemplateParser : SharpTemplate<Velocity> { }
	public class CurlyTemplateParser : SharpTemplate<DoubleCurly> { }

    class Program
    {
        private const string inputCurly = @"
    {{foreach x in list}}
    {{x}} {{x*2}} ({{x@row}}) {{x@oddeven}} [{{if x==3}}A{{elseif x==4}}B{{else}}C{{end}}]
    {{end}}

    {{xEl.Attribute(""test"")}}

";

		private const string inputVelocity = @"
	#foreach (x in list)
    $x ${x*2} ($x@row) $x@oddeven [#if (x==3)A#elseif (x==4)B#{else}C#end]
    #end

    ${xEl.Attribute(""test"")}

";

        private const string inputXml = @"
	<foreach var=""x"" in='list'>
    $x ${x*2} ($x@row) $x@oddeven [<if condition=""x==3"">A<elseif condition=""x==4"" />B<else/>C</if>]
    </foreach>
    <foreach var=""x"" in=""list""><item id=""id$x""/>$$x</foreach>

    ${xEl.Attribute(""test"")}

";


        static void Main()
        {
            SharpTemplate curlyParser = new CurlyTemplateParser();
			SharpTemplate velocityParser = new VelocityTemplateParser();
			SharpTemplate xmlParser = new SharpTemplate<Xml>();

            CSharpContext context = new CSharpContext();

            MockXElement xEl = new MockXElement();

            context.Set("list", new int[] {3, 4, 5});
            context.Set("xEl",xEl);

            string outputCurly = curlyParser.Render(inputCurly, context);
			string outputVelocity = velocityParser.Render(inputVelocity, context);
            string outputXml = xmlParser.Render(inputXml, context);

			Console.WriteLine("===========================");
			Console.Write(outputCurly);
			Console.WriteLine("===========================");
			Console.Write(outputVelocity);
			Console.WriteLine("===========================");
            Console.Write(outputXml);
            Console.WriteLine("===========================");

            Console.Read();
        }
    }

    public class MockXElement
    {
        public string Attribute(MockXName xName)
        {
            return "attr[" + xName + "]";
        }
    }

    public class MockXName
    {
        private string _name;

        public static implicit operator MockXName(string s)
        {
            MockXName xName = new MockXName();

            xName._name = s;

            return xName;
        }

        public override string ToString()
        {
            return _name;
        }
    }
}
